package com.jjb.www.ui.dialog;

import android.content.Context;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hjq.base.BaseAdapter;
import com.hjq.base.BaseDialog;
import com.hjq.shape.layout.ShapeLinearLayout;
import com.hjq.shape.view.ShapeButton;
import com.hjq.shape.view.ShapeImageView;
import com.hjq.shape.view.ShapeTextView;
import com.hjq.widget.layout.WrapRecyclerView;
import com.jjb.www.R;
import com.jjb.www.aop.SingleClick;
import com.jjb.www.bean.PostBean;
import com.jjb.www.http.api.ExamMessageApi;
import com.jjb.www.ui.adapter.AnswerSheetAdapter;
import com.jjb.www.ui.adapter.ChoosePostAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Author: crg
 * time:   2021/9/14 11:02
 * des:    选择岗位类型
 */
public final class AnswerSheetDialog {

    public static final class Builder
            extends BaseDialog.Builder<Builder>  {

        private AnswerSheetAdapter danxAdapter;
        private AnswerSheetAdapter pandAdapter;
        private AnswerSheetAdapter duoxAdapter;
        private AnswerSheetAdapter zonghAdapter;
        @Nullable
        private OnListener mListener;
        private ShapeButton mBtnCommin;

        private ShapeLinearLayout mLlDanx;
        private WrapRecyclerView mRvDanx;

        private ShapeLinearLayout mLlPand;
        private WrapRecyclerView mRvPand;

        private ShapeLinearLayout mLlDuox;
        private WrapRecyclerView mRvDuox;

        private ShapeLinearLayout mLlZongh;
        private WrapRecyclerView mRvZongh;


        private ShapeTextView mTvDanxNumber;
        private ShapeTextView mTvPandNumber;
        private ShapeTextView mTvDuoxNumber;
        private ShapeTextView mTvZonghNumber;






        public Builder(Context context) {
            super(context);
            setContentView(R.layout.dialog_answer_sheet);
            mBtnCommin = findViewById(R.id.btn_commin);
            mLlDanx = findViewById(R.id.ll_danx);
            mRvDanx = findViewById(R.id.rv_danx);
            mLlPand = findViewById(R.id.ll_pand);
            mRvPand = findViewById(R.id.rv_pand);
            mLlDuox = findViewById(R.id.ll_duox);
            mRvDuox = findViewById(R.id.rv_duox);
            mLlZongh = findViewById(R.id.ll_zongh);
            mRvZongh = findViewById(R.id.rv_zongh);

            mTvDanxNumber = findViewById(R.id.tv_danx_number);
            mTvPandNumber = findViewById(R.id.tv_pand_number);
            mTvDuoxNumber = findViewById(R.id.tv_duox_number);
            mTvZonghNumber = findViewById(R.id.tv_zongh_number);

            mRvDanx.setLayoutManager(new GridLayoutManager(getContext(),6));
            mRvPand.setLayoutManager(new GridLayoutManager(getContext(),6));
            mRvDuox.setLayoutManager(new GridLayoutManager(getContext(),6));
            mRvZongh.setLayoutManager(new GridLayoutManager(getContext(),6));

            danxAdapter = new AnswerSheetAdapter(getContext());
            danxAdapter.setOnItemClickListener((recyclerView, itemView, position) -> {
                mListener.onCompleted(getDialog(),danxAdapter.getItem(position));
                dismiss();
            });

            pandAdapter = new AnswerSheetAdapter(getContext());
            pandAdapter.setOnItemClickListener((recyclerView, itemView, position) -> {
                mListener.onCompleted(getDialog(),pandAdapter.getItem(position));
                dismiss();
            });

            duoxAdapter = new AnswerSheetAdapter(getContext());
            duoxAdapter.setOnItemClickListener((recyclerView, itemView, position) -> {
                mListener.onCompleted(getDialog(),duoxAdapter.getItem(position));
                dismiss();
            });

            zonghAdapter = new AnswerSheetAdapter(getContext());
            zonghAdapter.setOnItemClickListener((recyclerView, itemView, position) -> {
                mListener.onCompleted(getDialog(),zonghAdapter.getItem(position));
                dismiss();
            });

            mRvDanx.setAdapter(danxAdapter);
            mRvPand.setAdapter(pandAdapter);
            mRvDuox.setAdapter(duoxAdapter);
            mRvZongh.setAdapter(zonghAdapter);

            setOnClickListener(mBtnCommin);
        }

        public Builder setList(List<ExamMessageApi.Bean.FillListDTO> list) {
            //试题类型 1单选 2判断 3多选 4综合
            for (ExamMessageApi.Bean.FillListDTO fillListDTO:list) {
                if (fillListDTO.getType()==1){
                    mTvDanxNumber.setText("（共"+fillListDTO.getType_num()+"题，每题"+fillListDTO.getType_number_score()+"分）");
                    mLlDanx.setVisibility(View.VISIBLE);
                    danxAdapter.setData(fillListDTO.getNumber_list());
                }else if (fillListDTO.getType()==2){
                    mTvPandNumber.setText("（共"+fillListDTO.getType_num()+"题，每题"+fillListDTO.getType_number_score()+"分）");
                    mLlPand.setVisibility(View.VISIBLE);
                    pandAdapter.setData(fillListDTO.getNumber_list());
                }else if (fillListDTO.getType()==3){
                    mTvDuoxNumber.setText("（共"+fillListDTO.getType_num()+"题，每题"+fillListDTO.getType_number_score()+"分）");
                    mLlDuox.setVisibility(View.VISIBLE);
                    duoxAdapter.setData(fillListDTO.getNumber_list());
                }else if (fillListDTO.getType()==4){
                    mTvZonghNumber.setText("（共"+fillListDTO.getType_num()+"题，每题"+fillListDTO.getType_number_score()+"分）");
                    mLlZongh.setVisibility(View.VISIBLE);
                    zonghAdapter.setData(fillListDTO.getNumber_list());
                }
            }
            return this;
        }
        public Builder setTitle(String title) {
            return this;
        }
        public Builder setListener(OnListener listener) {
            mListener = listener;
            return this;
        }

        @SingleClick
        @Override
        public void onClick(View view) {
            if (view == mBtnCommin) {
                mListener.onCommin();
            }
        }

    }

    public interface OnListener {

        /**
         * 选择完成时回调
         */
        void onCompleted(BaseDialog dialog, ExamMessageApi.Bean.FillListDTO.NumberListDTO content);

        void onCommin();
    }
}
